package com.hr.dao;

import com.hr.model.Menu;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface MenuDAO
{
    @Results(id="menu",value = {
            @Result(id = true, property = "id", column = "id"),
            @Result(property = "url", column = "url"),
            @Result(property = "path", column = "path"),
            @Result(property = "component", column = "component"),
            @Result(property = "name", column = "name"),
            @Result(property = "iconCls", column = "iconCls"),
            @Result(property = "keepAlive", column = "keepAlive"),
            @Result(property = "require", column = "require"),
            @Result(property = "parentId", column = "parentId"),
            @Result(property = "enabled", column = "enabled"),
            @Result(property = "children", column = "id",one=@One(select = "com.hr.dao.MenuDAO.getMenusByParentId"))
    })
    @Select("select * from menu where id=#{mid}")
    Menu getMenuByMId(@Param("mid")int mid);

    @ResultMap("menu")
    @Select("select * from menu where parentId is null")
    Menu getMasterMenu();

    @ResultMap("menu")
    @Select("select * from menu where parentId =#{parentId}")
    List<Menu> getMenusByParentId(@Param("parentId")int parentId);

    @ResultMap("menu")
    @Select("select * from menu ")
    List<Menu> getAllMenus();
}
